<%@ page language="java" contentType="text/html; charset=utf-8"%>

<%@page import="cn.edu.scut.fsearch.comm.comm"%>
<%@page import="cn.edu.scut.fsearch.user.UserSearchOption"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<head>
	<%
		int perPage = comm.NUM_PER_PAGE;
		UserSearchOption preOption = new UserSearchOption();
		preOption.getPreOptions(request);
		int type = preOption.getType().ordinal();
		String etemp = preOption.getEduSeString(preOption.getEduSE());
		String utemp = preOption.getUniversitySeString(preOption.getUniversitySE());
		String ttemp = preOption.getTopicString(preOption.getTopicSE());
	%>

	<title>下一代互联网分布式搜索引擎平台</title>
	<link href="css/main.css" rel="stylesheet" type="text/css" />
	<link href="css/suggest.css" rel="stylesheet" type="text/css" />
	<!-- 引入一些js -->
	<script type="text/javascript" src="script/jquery.js"  language="javascript"></script>
	<script type="text/javascript" src="script/json.js"></script>
	<script type="text/javascript" src="script/collector.js"></script>
	<script type="text/javascript" src="script/suggest.js" language="javascript"></script>
	<script type="text/javascript" src="script/myPageShow.js" language="javascript"></script>

	<script type="text/javascript">
	/*首先恢复用户上次的选择*/
	var stype = "<%=type%>";
	var ese = "<%=etemp%>";
	var use = "<%=utemp%>";
	var tse = "<%=ttemp%>";
	ese = ese.split(",");
	use = use.split(",");
	tse = tse.split(",");

/*展开各大高校的节点以供选择*/	
$(function(){
  $(".oo").toggle(
  function () {
    $("#hid").slideDown("fast");
	$(".oo").html("关闭");
  },
  function () {
    $("#hid").slideUp("fast");
	$(".oo").html("更多");
  }
); 
})

$(document).ready(function(){
	var checklist = document.getElementsByName ("checkeduse");
	for(var i=0;i<ese.length;i++)
    {
    	if(ese[i] != "" && ese[i] != null)
    	{
    		var index = parseInt(ese[i]);
			checklist[index].checked = 1;
		}
	}
	 checklist = document.getElementsByName ("checkgxse");
	 for(var i=0;i<use.length;i++)
	 {
	 	if(use[i] != "" && use[i] != null)
	 	{
			var index = parseInt(use[i]);
			checklist[index].checked = 1;
		}
	 }
	 //checklist = document.getElementsByName ("topicse");
	// for(var i=0;i<tse.length;i++)
	 //{
	 //	if(tse[i] != "" && tse[i] != null)
	 //	{
		//	var index = parseInt(tse[i]);
		//	checklist[index].checked = 1;
		//}
	// }
	if(tse[0] != "")
		document.getElementsByName ("topicse")[tse[0]].checked = true;
	document.getElementsByName ("ipv")[stype].checked = true;
	document.getElementById("hid").style.display = "block";
});

/*当用户选择发生改变时做出回应*/	
function selectChange(c){
    if(c==1)
	{
	  var checklist = document.getElementsByName ("checkeduse");
	  for(var i=0;i<checklist.length;i++)
	  {
		 checklist[i].checked = 0;
	  }
	  checklist = document.getElementsByName ("checkgxse");
	  for(var i=0;i<checklist.length;i++)
	  {
		 checklist[i].checked = 0;
	  }
	  checklist = document.getElementsByName ("topicse");
	  for(var i=0;i<checklist.length;i++)
	  {
		 checklist[i].checked = 0;
	  }
	}
	else if(c==2)
	{
	  var checklist = document.getElementsByName ("checkeduse");
	  for(var i=0;i<checklist.length;i++)
	  {
		 if(checklist[i].checked == 1)
		 {
		 	checklist[i].checked = 0;
		 }
		 else
		 {
		 	checklist[i].checked = 1;
		 }
	  } 
	  checklist = document.getElementsByName ("checkgxse");
	  for(var i=0;i<checklist.length;i++)
	  {
		 if(checklist[i].checked == 1)
		 {
		 	checklist[i].checked = 0;
		 }
		 else
		 {
		 	checklist[i].checked = 1;
		 }
	  }
	  checklist = document.getElementsByName ("topicse");
	  for(var i=0;i<checklist.length;i++)
	  {
		 if(checklist[i].checked == 1)
		 {
		 	checklist[i].checked = 0;
		 }
		 else
		 {
		 	checklist[i].checked = 1;
		 }
	  } 
	}
	else if(c==0)
	{
	  var checklist = document.getElementsByName ("checkeduse");
	  for(var i=0;i<checklist.length;i++)
	  {
		 checklist[i].checked = 1;
	  } 
	  checklist = document.getElementsByName ("checkgxse");
	  for(var i=0;i<checklist.length;i++)
	  {
		 checklist[i].checked = 1;
	  }
	  checklist = document.getElementsByName ("topicse");
	  for(var i=0;i<checklist.length;i++)
	  {
		 checklist[i].checked = 1;
	  }
	}
}

function search(perPage)
{	
	  var qtext = document.form1.searchtext;
	  if(qtext.value == null || qtext.value == "")
	  {
	  	 alert("请输入查询关键字!");
	  	 return false;
	  }
	  var selNode = validSENode();
	  var ipv = getSourceType();
	  if(selNode != ":" && ipv != "")
	  {
	  	//记录搜索的url
	  	var url="searchAction.do?method=search&searchText="+encodeURI(qtext.value);
	  	url += "&page=0&perPage="+perPage;;
	  	url += "&ipv="+ipv;
	  	url += "&selNode="+selNode;
	  	url += "&hs=0";
	  	url += "&span=";
	  	document.form1.action = url;
		document.form1.submit();
		return true;
	  }
	  else{
	  	alert("请至少选择一个搜索节点");
	  	return false;
	  }
}

/*获取选择的搜索引擎节点的个数*/
function validSENode()
{
	 //获取教育网选择的节点
	 var result = "";
	 var tmpresult = "";
 	 var checklist = document.getElementsByName ("checkeduse");
	 var j=0;
	 for(var i=0;i<checklist.length;i++)
	 {
		if(checklist[i].checked == 1)
		{
		  tmpresult += checklist[i].value+",";
		}
	 }
	 if(tmpresult == "")
	 	tmpresult = "-1";
	 result += tmpresult+":";
	 //获取高校选择的节点
	 checklist = document.getElementsByName ("checkgxse");
	 j = 0;
	 tmpresult = "";
	 for(var i=0;i<checklist.length;i++)
	 {
		if(checklist[i].checked == 1)
		{
		  tmpresult += checklist[i].value+",";
		}
	 }
	 if(tmpresult == "")
	 	tmpresult = "-1";
	 result += tmpresult+":";
	 //获取专题选择的节点
	 checklist = document.getElementsByName ("topicse");
	 j = 0;
	 tmpresult = "";
	 for(var i=0;i<checklist.length;i++)
	 {
		if(checklist[i].checked == 1)
		{
		  tmpresult += checklist[i].value+",";
		}
	 }
	 if(tmpresult == "")
	 	tmpresult = "-1";
	 result += tmpresult;
	 
	 return result;
}

function getSourceType()
{
	 var checklist = document.getElementsByName ("ipv");
	 for(var i=0;i<checklist.length;i++)
	 {
		if(checklist[i].checked == 1)
		{
		  return checklist[i].value;
		}
	 }
}
</script>

</head>

<body>
	<form name="form1" method="post"
		onsubmit="return search('<%=perPage%>')">
		<div id="logobg" align="center">
			<div id="logo">
				<a href="aboutus.jsp"><img src="images/logo.jpg"
						border="0" /> </a>
			</div>
		</div>
		<table align="center">
			<tr>
				<td>
					<div id="mid">
						<div id="midcontent">
							<div id="search">
								<table width="570" height="80%">
									<tr>
										<td>
											<div id="searchinput">
												<input type="text" id="searchtext" />
												<input id="searchsubmit" type="submit" value="" />
											</div>
										</td>
										<td>
											<p>
												<a id="ipv6link" href="ipv6statistic.jsp">资源分布</a>
												<br>
												<a id="ipv6link" href="advanced.jsp">高级搜索</a>
											</p>
										</td>
									</tr>
								</table>
							</div>
							<div id="sort" align="center">

								<div id="sortcheck">
									<table width="100%">
										<tr>
											<td valign="top">
												<img src="images/sortcheck0.jpg" />
											</td>
											<td>
												<table width="100%">
													<tr>
														<td width="25%" align="left">
															<input type="radio" name="ipv" value="0" />
															IPv4 资源
														</td>
														<td width="25%" align="left">
															<input type="radio" name="ipv" value="1" />
															IPv6 资源
														</td>
														<td width="30%" align="left">
															<input type="radio" name="ipv" value="2" />
															IPv4/IPv6 资源
														</td>
														<td width="25%">
															&nbsp;
														</td>
													</tr>
												</table>
											</td>
										</tr>
										<tr>
											<td valign="top">
												<img src="images/sortcheck1.jpg" />
											</td>
											<td>
												<table width="100%" align="left">
													<tr>
														<td width="25%" align="left">
															<input type="checkbox" name="checkeduse" value="0" />
															华南木棉
														</td>
														<td width="25%" align="left">
															<input type="checkbox" name="checkeduse" value="1" />
															北大天网
														</td>
														<td width="25%" align="left">
															<input type="checkbox" name="checkeduse" value="2" />
															清华指南针
														</td>
														<td width="25%">
															<div id="sortselect">
																<select onchange="selectChange(this.value);">
																	<option value="0">
																		全部选择
																	</option>
																	<option value="1">
																		全部取消
																	</option>
																	<option value="2">
																		全部反选
																	</option>
																</select>
															</div>
														</td>
													</tr>
												</table>
											</td>
										</tr>
										<tr>
											<td valign="top">
												<img src="images/topicse.jpg" />
											</td>
											<td>
												<table width="100%" align="left">
													<tr>
														<td width="25%" align="left">
															<input type="radio" name="topicse" value="0" />
															清华科技新闻
														</td>
														<td width="25%" align="left">
															<input type="radio" name="topicse" value="1" />
															北大科研论文
														</td>
														<td width="25%" align="left">
															<input type="radio" name="topicse" value="2" />
															华工教育新闻
														</td>
														<td width="25%">
														</td>
													</tr>
												</table>
											</td>
										</tr>
										<tr>
											<td valign="top">
												<img src="images/sortcheck3.jpg" />
											</td>
											<td>
												<table width="600" style="border: none;">
													<tr>
														<td width="25%" align="left">
															<input type="checkbox" name="checkgxse" value="0" />
															<img src="images/pku.jpg"
																style="height: 15px; width: 15px" />
															北京大学
														</td>
														<td width="25%" align="left">
															<input type="checkbox" name="checkgxse" value="1" />
															<img src="images/tsing.jpg"
																style="height: 15px; width: 15px" />
															清华大学
														</td>
														<td width="25%" align="left">
															<input type="checkbox" name="checkgxse" value="2" />
															<img src="images/scut.jpg"
																style="height: 15px; width: 15px" />
															华南理工大学
														</td>
														<td width="25%" align="left">
															<input type="checkbox" name="checkgxse" value="3" />
															<img src="images/huazhong.jpg"
																style="height: 15px; width: 15px" />
															华中科技大学
														</td>
													</tr>
												</table>
												<div id="hid">
													<table width="100%">
														<tr>
															<td width="25%" align="left">
																<input type="checkbox" name="checkgxse" value="4" />
																<img src="images/dongbei.jpg"
																	style="height: 15px; width: 15px" />
																东北大学
															</td>
															<td width="25%" align="left">
																<input type="checkbox" name="checkgxse" value="5" />
																<img src="images/dongnan.jpg"
																	style="height: 15px; width: 15px" />
																东南大学
															</td>
															<td width="25%" align="left">
																<input type="checkbox" name="checkgxse" value="6" />
																<img src="images/beiyou.jpg"
																	style="height: 15px; width: 15px" />
																北京邮电大学
															</td>
															<td width="25%" align="left">
																<input type="checkbox" name="checkgxse" value="7" />
																<img src="images/dianzi.jpg"
																	style="height: 15px; width: 15px" />
																电子科技大学
															</td>
														</tr>
														<tr>
															<td width="25%" align="left">
																<input type="checkbox" name="checkgxse" value="8" />
																<img src="images/shangjiao.jpg"
																	style="height: 15px; width: 15px" />
																上海交通大学
															</td>
															<td width="25%" align="left">
																<input type="checkbox" name="checkgxse" value="9" />
																<img src="images/xijiao.jpg"
																	style="height: 15px; width: 15px" />
																西安交通大学
															</td>
														</tr>

													</table>
												</div>
												<a href="#" class="oo" onfocus="blur() ">关闭</a>
											</td>
										</tr>
									</table>
								</div>
								<div style="clear: both"></div>

							</div>
						</div>
					</div>

				</td>
			</tr>
			<tr>
				<td>
					<div id="copyright">
						<p>
							&nbsp;
						</p>
						<p>
							&nbsp;
						</p>
						<p>
							版权所有 华南理工大学广东省网络重点实验室&nbsp;

						</p>
						<p>
							Copyright (c) 2010 SCUT CCNL All Rights Reserved &nbsp;
							<a href="aboutus.jsp"><font
								style="color: #aaa; text-decoration: none">关于我们</font> </a>
						</p>
					</div>
				</td>
			</tr>
		</table>
	</form>
</body>
</html:html>
